home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Arashi 1.1.1 / source code / Game Source / jam src / STStars.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-09  |  2.8 KB  |  146 lines  |  [TEXT/KAHL]

  1. /*/
  2.      Project Arashi: STStars.c
  3.      Major release: Version 1.1d2, 9/5/95
  4.  
  5.      Last modification: Wednesday, September 9, 1992, 21:45
  6.      Created: Sunday, January 6, 1991, 7:20
  7.  
  8.      Copyright © 1991-1992, Juri Munkki
  9. /*/
  10.  
  11. #include "VA.h"
  12. #include "STORM.h"
  13.  
  14. #define  ARRIVALSPEED        8
  15. #define  CENTERSTARTRATIO    96
  16.  
  17. typedef    struct
  18. {    
  19.     int        index[2];
  20.     int        direction[2];
  21.     int        ratio;
  22.     char    color;
  23.     char    state;
  24.     int        *notify;
  25. }    CenterStar;
  26.  
  27. enum    {    available,    used,    unavailable    };
  28.  
  29. CenterStar    *AllStars;
  30. int            TotalStars;
  31. int            FirstUnused;
  32.  
  33. void    AllocCStars()
  34. {
  35.     TotalStars=MAXCENTERSTARS;
  36.     AllStars=(CenterStar *)NewPtr(sizeof(CenterStar)*(MAXCENTERSTARS+1));
  37.     FirstUnused=0;
  38. }
  39. void    InitCStars()
  40. {
  41.     register    int        i,d;
  42.     
  43.     FirstUnused=0;
  44.     for(i=0;i<TotalStars;i++)
  45.     {    for(d=0;d<2;d++)
  46.         {    AllStars[i].index[d]=VAPosRandom() % ww.starsegs;
  47.             AllStars[i].direction[d]=((VARandom() & 1)<<1) -1;
  48.         }
  49.         AllStars[i].ratio=CENTERSTARTRATIO;
  50.         AllStars[i].color=i & 7;
  51.         AllStars[i].state=available;
  52.     }
  53. }
  54. void    UpdateCStars()
  55. {
  56.     register    int            i,d;
  57.     register    int            x1,x0,y1,y0;
  58.     register    CenterStar    *csp;
  59.                 CenterStar    temp;
  60.                 int            availcount;
  61.     
  62.     availcount=ThisLevel.starCount;
  63.  
  64.     csp=AllStars;
  65.     VA.color=5;
  66.     for(i=0;i<TotalStars;i++)
  67.     {    x1=    ww.starx[csp->index[1]][1];
  68.         x0=    ww.starx[csp->index[0]][0]-x1;
  69.         y1=    ww.stary[csp->index[1]][1];
  70.         y0=    ww.stary[csp->index[0]][0]-y1;
  71.  
  72.         if(csp->state==used)
  73.         {    csp->ratio+=ARRIVALSPEED;
  74.             if(csp->ratio>=256)
  75.             {    csp->ratio=CENTERSTARTRATIO;
  76.                 csp->state=available;
  77.                 csp->color=0;
  78.                 temp=*csp;
  79.                 
  80.                 for(d=0;d<2;d++)
  81.                 {    csp->index[d]=VAPosRandom() % ww.starsegs;
  82.                     csp->direction[d]=((VARandom() & 1)<<1) -1;
  83.                 }
  84.                 *csp=AllStars[--FirstUnused];
  85.                 AllStars[FirstUnused]=temp;
  86.                 *(temp.notify)= -1-temp.index[0];
  87.             }
  88.         }
  89.         else
  90.         {    if(availcount-- > 0)
  91.             {    csp->color++;
  92.                 if(csp->color>6)    csp->color=0;
  93.             }
  94.             else
  95.             {    csp->state=unavailable;
  96.             }
  97.         }
  98.         
  99.         if(csp->state!=unavailable)    
  100.         {    VA.color=csp->color;
  101.             VASafePixel(    x1+(long)x0*csp->ratio/256,
  102.                             y1+(long)y0*csp->ratio/256);
  103.         }
  104.         else
  105.         {    csp->state=available;
  106.         }
  107.     
  108.         for(d=0;d<2;d++)
  109.         {    csp->index[d]+=csp->direction[d];
  110.             if(ww.wraps)
  111.             {    if(csp->index[d]<0)
  112.                     csp->index[d]+=ww.starsegs;
  113.                 else
  114.                 if(csp->index[d]>=ww.starsegs)
  115.                     csp->index[d]-=ww.starsegs;
  116.             }
  117.             else
  118.             {    if(csp->index[d]<=0)
  119.                 {    csp->index[d]=0;
  120.                     csp->direction[d]=-csp->direction[d];
  121.                 }
  122.                 if(csp->index[d]>=ww.starsegs)
  123.                 {    csp->index[d]=ww.starsegs;
  124.                     csp->direction[d]=-csp->direction[d];
  125.                 }
  126.             }
  127.         }
  128.         csp++;
  129.     }
  130. }
  131.  
  132. void    StarApproach(notify,color)
  133. int        *notify;
  134. int        color;
  135. {    
  136.     if(FirstUnused>=TotalStars)
  137.     {    *notify=-(((unsigned int)VARandom()) % (ww.numsegs-1) + 1);
  138.     }
  139.     else
  140.     {    AllStars[FirstUnused].state=used;
  141.         AllStars[FirstUnused].notify=notify;
  142.         AllStars[FirstUnused].color=color;
  143.         FirstUnused++;
  144.         *notify=0;
  145.     }
  146. }